<!-- <script>
    // 并集
    // [1,2,3] 并 [4,5,6] ==> [1,2,3,4,5,6]
    // [1,2,3,3] 并 [4,5,6,6] ==> [1,2,3,4,5,6]
    // [1,2,3,3] 并 [3,6,6] ==> [1,2,3,6]
    let arr1 = [1,2,3,3];
    let arr2 = [4,5,6,3,2,4,9];
    function union(arr1,arr2){
        let res = new Set([...arr1,...arr2])
        return [...res]
    }
    let newArr = union(arr1,arr2);
    console.log(newArr)
</script> -->








<!-- <script>
    // 交集
    // [1,2,3] 交 [3,4,5,6] ==> [3]
    // [1,2,3] 交 [7,8,9] ==> []
    // [1,2,3] 交 [1,2,3] ==> [1,2,3]
    let arr1 = [1,2,3,3];
    let arr2 = [3,4,5,5];
    function intersection(arr1,arr2){
        let s1 = new Set(arr1)
        let s2 = new Set(arr2)
        let newArr = [...s1].filter(item=>{
            return s2.has(item)
        })
        return newArr
    }
    let newArr = intersection(arr1,arr2);
    console.log(newArr)
</script> -->













<script>
    // 差集
    // [1,2,3] 差 [3,4,5] ==> [1,2]
    // [3,4,5] 差 [1,2,3] ==> [4,5]

    let arr1 = [1, 2, 3];
    let arr2 = [3, 4, 5];
    function except(arr1, arr2) {
        let s1 = new Set(arr1)
        let s2 = new Set(arr2)
        let newArr = [...s1].filter(item => {
            return !s2.has(item)
        })
        return newArr;
    }

    console.log(except(arr1, arr2)) // [1,2]
    console.log(except(arr2, arr1))  // [4,5]
</script>